package 设计模式.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @功能
 * 组合模式
 * @创建时间 2020/5/3
 */
public interface AbstractFile {
    void killVirus();
}
class ImageFile implements AbstractFile{
    public ImageFile(String name) {
        this.name = name;
    }

    private String name;
    @Override
    public void killVirus() {
        System.out.println("--图像文件"+name+"被删除");
    }
}
class TextFile implements AbstractFile{
    public TextFile(String name) {
        this.name = name;
    }

    private String name;
    @Override
    public void killVirus() {
        System.out.println("--文本文件"+name+"被删除");
    }
}
class VideoFile implements AbstractFile{
    public VideoFile(String name) {
        this.name = name;
    }

    private String name;
    @Override
    public void killVirus() {
        System.out.println("--视频文件"+name+"被删除");
    }
}
class Folder implements AbstractFile{
    public Folder(String name) {
        this.name = name;

    }

    private String name;


    public void add(AbstractFile file){
        list.add(file);
    }

    public void remove(AbstractFile file){
        list.remove(file);
    }

    public AbstractFile getChild(int index){
        return list.get(index);
    }
    private List<AbstractFile> list  = new ArrayList<>();
    @Override
    public void killVirus() {
        System.out.println("文件夹"+name+"查杀");
        for(AbstractFile file:list){
            file.killVirus();
        }
    }
}